package com.ttms.dao.impl;
import com.ttms.dao.UserDao;
import com.ttms.pojo.User;
import java.util.List;
public class UserDaoImpl extends BaseDao implements UserDao {
    @Override
    public User queryUserByUsername(String username) {
        String sql= "select `id`,`username`,`phone`,`password` from user where username=?";
        return queryForOne(User.class,sql,username);
    }

    @Override
    public User queryUserByUsernameAndPassword(String phone, String password) {
        String sql= "select `id`,`username`,`phone`,`password`,`type` from user where phone=? and password=?";
        return queryForOne(User.class,sql,phone, password);
    }

    @Override
    public int resetHead(String head_path) {
        String sql="update user set `head_path` = ? where id = 1";
        return update(sql, head_path);
    }

    @Override
    public int savaUser(User user) {
        String sql="insert into user(`username`,`password`,`phone`) values( ?, ?, ?)";
        return update(sql,user.getUsername(),user.getPassword(),user.getPhone());
    }

    @Override
    public int resetPassWord(String password ,int id) {
        String sql="update user set `password` = ? where id = ?";
        return update(sql, password,id);
    }

    @Override
    public int rename(String phone, String username, int id) {
        String sql="update user set `phone` = ? ,`username` = ? where id = ?";
        return update(sql, phone,username,id);
    }

    @Override
    public List<User> queryUsers(int begin,int pageNo) {
        String sql = "select * from user limit ?,?";
        return queryForList(User.class, sql,begin,pageNo);
    }

    @Override
    public Integer queryForPageTotalCount() {
        String sql = "select count(*) from user";
        Number count = (Number) queryForSingleValue(sql);
        return count.intValue();
    }

    @Override
    public User queryUserById(int id) {
        String sql ="select * from user where id=?";
        return queryForOne(User.class, sql, id);
    }

    @Override
    public List<User> queryForPageItems(int begin, int pageSize) {
        String sql = "select * from user limit ?,?";
        return queryForList(User.class,sql,begin,pageSize);
    }

    @Override
    public User queryUserByPhone(String phone) {
        String sql ="select * from user where phone=?";
        return queryForOne(User.class, sql ,phone);
    }
}
